import Vue from 'vue'
import VueRouter from 'vue-router'


Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/Login',
  },
  {
    //登录
    path: '/Login',
    component: () => import('../views/Login/Login')
  },
  {
    path: '/Home',
    redirect: '/Housing',
    component: () => import('../views/Home/Home'),
    children: [
      {
        //房源管理
        path: '/Housing',
        component: () => import('../views/Housing/Housing'),
        meta: {
          isload: true
        }
      },
      {
        //直播管理
        path: '/Live',
        component: () => import('../views/Live/Live'),
        meta: {
          isload: true
        }
      },
      {
        //团购管理
        path: '/Group',
        component: () => import('../views/Group/Group'),
        meta: {
          isload: true
        }
      },
      {
        //审核管理
        path: '/Audit',
        component: () => import('../views/Audit/Audit'),
        meta: {
          isload: true
        }
      },
      {
        //订单管理
        path: '/Order',
        component: () => import('../views/Order/Order'),
        meta: {
          isload: true
        }
      },
      {
        //资讯管理
        path: '/Information',
        component: () => import('../views/Information/Information'),
        meta: {
          isload: true
        }
      },
      {
        //经纪人管理
        path: '/Broker',
        component: () => import('../views/Broker/Broker'),
        meta: {
          isload: true
        }
      },
      {
        //直播详情
        path: '/Detail/:id',
        component: () => import('../views/Detail/Detail')
      },
    ]
  },

]

const router = new VueRouter({
  routes
})
//路由拦截
router.beforeEach((to, form, next) => {
  if (to.meta.isload) {
    if (localStorage.getItem('token')) {
      next()
    } else {
      next('/Login')
    }
  } else {
    next()
  }
})
export default router
